package com.gochic.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.gochic.mid.User;

public class UserServlet extends HttpServlet {
	private static final long serialVersionUID = -5455563108056977893L;
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");

		String url = "/user.jsp";
		int index = -1;
		try {
			index = Integer.parseInt(request.getParameter("act"));
		} catch (NumberFormatException nfe) {
		}
		switch (index) {
		case 1://Constant.Action.RenderInterface:
			List<User> users = User.getAllUsers();
			request.setAttribute("users", users);
			/*
			List<Tag> sites = Site.getAllSites();
			List<Customer> custs = Customer.getAllCustomers();
			request.setAttribute("custs", custs);
			request.setAttribute("act", Constant.Action.AddEntity);
			*/
			break;
		case 2:
			/*
			custs = addCustomer(request);
			url = "customer.do?act=" + Constant.Action.RenderInterface;
			break;
			*/
		default:
			/*
			request.setAttribute("err",
					Constant.Error.Customer.WrongActionIndex);
			*/
		}
		RequestDispatcher dispatcher = request.getRequestDispatcher( url );
		try {
			dispatcher.forward(request, response);
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
